package project.active;

import java.sql.SQLException;

import model.pojo.Employee;
import project.dao.TestProjectDAO;
import project.model.PrProject;
import project.model.PrTestProject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import approve.action.R;

public class ProcessButtonEditManagerProject extends Activity{
	private TextView currNameProject;
	private EditText editTitle,editContent;
	private Button buttonUpdate, buttonCancel;
	
	private String lang="EN",database="admin";
	private Employee emp = new Employee();
	private PrProject prProject  = null;
	private PrTestProject prTestProject = null;
	TextView logout,username;
	Bundle language;
	TextView lbTitle,lbContent;
	
	
	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
		}
		return database;
	}
	public String getLang(){
    	Bundle extras = getIntent().getExtras();
    	if(extras != null){
    		lang = extras.getString("lang");
    	}
    	return lang;
    }
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.buttonediterrormanagerproject);
		language = getIntent().getExtras().getBundle(getLang());
		currNameProject = (TextView)findViewById(R.id.curProjectName);
		editTitle = (EditText)findViewById(R.id.texttitle);
		editContent = (EditText)findViewById(R.id.textcontent);
		
		lbTitle = (TextView)findViewById(R.id.idlabletitle);
		lbContent = (TextView)findViewById(R.id.idlabelcontent);
		
		buttonUpdate = (Button)findViewById(R.id.idbuttonupdate);
		buttonCancel = (Button)findViewById(R.id.idbuttoncancel);
		
		Intent intent = this.getIntent();
		prProject = (PrProject)intent.getSerializableExtra("prproject");
		emp =(Employee)intent.getSerializableExtra("emp");
		prTestProject = (PrTestProject)intent.getSerializableExtra("prprojecttest");
		
		currNameProject.setText(prProject.getNameProject());
//		editTitle.setText(prTestProject.getTitle());
		editTitle.setText(prTestProject.getTitleview());
		editContent.setText(prTestProject.getText());
		
		buttonUpdate.setOnClickListener(processButtonUpdate);
		buttonCancel.setOnClickListener(processButtonCancel);
		
		logout=(TextView)findViewById(R.id.logout);
		username=(TextView)findViewById(R.id.username);
		logout.setText(language.getString("Logout"));
		
		logout.setOnClickListener(listenerLogout);
		username.setText(emp.getUserName());
		
		lbTitle.setText(language.getString("title"));
		lbContent.setText(language.getString("content"));
		buttonCancel.setText(language.getString("ac_Cancel"));
		buttonUpdate.setText(language.getString("ac_ma_Update"));
	}
private OnClickListener listenerLogout=new OnClickListener() {
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent i=new Intent(ProcessButtonEditManagerProject.this, LogoutActivity.class);
			i.putExtra("database", getDatabase());
			startActivity(i);
		}
	};
	private OnClickListener processButtonUpdate = new OnClickListener() {
		
		
		public void onClick(View v) {
				TestProjectDAO.updateDetailTest(editTitle.getText().toString(),editContent.getText().toString(), prTestProject.getIdTest(), getDatabase());
				Intent intent = new Intent(ProcessButtonEditManagerProject.this,ListErrorProjectManager.class);
				intent.putExtras(getIntent().getExtras());
				intent.putExtra("prproject", prProject);
				intent.putExtra("empl", emp);
				intent.putExtra("database", getDatabase());
				intent.putExtra("lang", lang);
				intent.putExtra("errorproject", prTestProject);
				
				startActivity(intent);
		}
	};
	
	private OnClickListener processButtonCancel = new OnClickListener() {
		
		
		public void onClick(View v) {
			Intent intent = new Intent(ProcessButtonEditManagerProject.this,ProjectManagerErrorDetail.class);
			intent.putExtras(getIntent().getExtras());
			intent.putExtra("project", prProject);
			intent.putExtra("em", emp);
			intent.putExtra("errorproject", prTestProject);
			intent.putExtra("database",getDatabase());
			intent.putExtra("lang", lang);
			
			startActivity(intent);
		}
	};

}
